var i;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var BundleConfig = require("AA_BundleConfig");
var ResKeeper = require("AA_ResKeeper");
var Excel = require("AA_Excel");
var NodePoolMag = require("AA_NodePoolMag");
var UI_BulletBombCollider = require("AA_UI_BulletBombCollider");
var _decorator = cc._decorator;
var _ccclass = _decorator.ccclass;
var _property = _decorator.property;

var _def_UI_BulletBomb = function (e) {
  function _creator() {
    var t = null !== e && e.apply(this, arguments) || this;
    t.bulletId = 1;
    t.nowbox = null;
    t.spr = null;
    t.attack = 0;
    t.attackfanwei = 0;
    t.isbaoji = false;
    t.isbisha = false;
    t.attackfang = null;
    t.nowdirection = 0;
    t.nowpos = null;
    t.tw = null;
    t.createtime = 0;
    t.ispengzhuang = false;
    t.bulletspeed = 40;
    t.issend = false;
    return t;
  }
  __extends(_creator, e);
  _creator.prototype.initBullet = function (e, t) {
    return __awaiter(this, undefined, undefined, function () {
      var o;
      var n;
      var i;
      var a;
      var r;
      return __generator(this, function (c) {
        switch (c.label) {
          case 0:
            this.attack = e.attack;
            this.attackfang = e.playerId;
            this.isbaoji = e.isbaoji;
            o = e.skinlevel;
            this.isbisha = e.isbisha;
            this.createtime = new Date().getTime();
            return [4, this._loadRes(BundleConfig.BundleNames.Common, "common/" + "res/player/player8_" + (o + 1), cc.SpriteFrame)];
          case 1:
            n = c.sent();
            this.spr.spriteFrame = n;
            this.nowpos = t;
            i = cc.v2();
            cc.Vec2.subtract(i, cc.v2(t.x, t.y), this.node.getPosition());
            this.nowdirection = Math.atan2(i.y, i.x);
            this.issend = true;
            a = Excel.Excel.shuiguobuff(this.attackfang.sgtianfuid);
            if (a) {
              this.attackfanwei = a.value[0];
            }
            this.tw && this.tw.stop();
            r = cc.tween(this.spr.node).to(.5, {
              scale: .9
            }).to(.5, {
              scale: 1
            });
            this.tw = cc.tween(this.spr.node).repeatForever(r).start();
            return [2];
        }
      });
    });
  };
  _creator.prototype.getBiSha = function () {
    return this.isbisha;
  };
  _creator.prototype.getBombFanWei = function () {
    return this.attackfanwei;
  };
  _creator.prototype.sendBullet1 = function () {
    this.moveBullet(this.nowdirection);
  };
  _creator.prototype.moveBullet = function (e) {
    var t = cc.Vec2.distance(cc.v2(this.nowpos.x, this.nowpos.y), this.node.getPosition());
    var o = this.bulletspeed;
    t < this.bulletspeed && (o = t);
    this.node.x += Math.cos(e) * o;
    this.node.y += Math.sin(e) * o;
    if ((t = cc.Vec2.distance(cc.v2(this.nowpos.x, this.nowpos.y), this.node.getPosition())) <= 10) {
      this.issend = false;
      this.node.x = this.nowpos.x;
      this.node.y = this.nowpos.y;
    }
  };
  _creator.prototype.getBulletAttack = function () {
    return this.attack;
  };
  _creator.prototype.getNowMosterNode = function () {
    var e = this.attackfang.mosterNodes.children;
    var t = [];
    for (var o = 0; o < e.length; o++) {
      var n = e[o];
      var i = cc.Vec2.distance(n.getPosition(), this.node.getPosition());
      (i -= n.width / 2 + this.node.width / 2) <= this.attackfanwei && t.push(n);
    }
    return t;
  };
  _creator.prototype.hideBullet = function () {
    this.issend = false;
    NodePoolMag.NodePoolMag.instance.recycleNode("bullet_2", this.node);
  };
  _creator.prototype.setBoxState = function (e) {
    this.ispengzhuang = e;
  };
  _creator.prototype.onUpdate = function () {
    this.issend && this.sendBullet1();
  };
  _creator.prototype.pengZhuangMoster = function (e) {
    if (this.ispengzhuang) {
      var t = e.children;
      for (var o = 0; o < t.length; o++) {
        var n = t[o];
        if (cc.Vec2.distance(n.getPosition(), this.node.getPosition()) <= 20) {
          this.nowbox.getComponent(UI_BulletBombCollider.default).onMyCollisionEntyer(n);
          break;
        }
      }
    }
  };
  __decorate([_property()], _creator.prototype, "bulletId", undefined);
  __decorate([_property(cc.Node)], _creator.prototype, "nowbox", undefined);
  __decorate([_property(cc.Sprite)], _creator.prototype, "spr", undefined);
  return __decorate([_ccclass], _creator);
}(ResKeeper.default);
exports.default = _def_UI_BulletBomb;